package com.ext.aic.apis.user;

import android.content.Context;

import androidx.lifecycle.LifecycleOwner;

import com.ext.aic.apis.ApiDefine;
import com.ext.aic.apis.ApiPaths;
import com.ext.aic.builder.ParamsBuilder;
import com.ext.aic.apis.RequestResponse;
import com.ext.aic.beans.Pagination;
import com.ext.aic.beans.TaskItem;
import com.ext.aic.beans.params.TaskListParams;
import com.ext.aic.beans.response.TaskResponse;
import com.hjq.http.EasyHttp;

import java.util.List;

public class TaskListRequest {

    protected void onTaskSuccess(List<TaskItem> items, Pagination pagination) {

    }

    public void request(Context context, LifecycleOwner lifecycleOwner, TaskListParams params) {
        ParamsBuilder builder = new ParamsBuilder();
        builder.add("page", params.getPage());
        builder.add("pageSize", params.getPageSize());
        EasyHttp.get(lifecycleOwner)
                .api(new ApiDefine(ApiPaths.taskList, builder))
                .request(new RequestResponse<TaskResponse>(context, true) {
                    @Override
                    protected void onSuccess(TaskResponse response) {
                        onTaskSuccess(response.getData(), response.getPagination());
                    }
                });

    }
}
